import rclpy

from rclpy.node import Node

import time
class ParamTest(Node):
    def __init__(self,node_name):
        super().__init__(node_name)
        self.get_logger().info(f"{node_name} 启动")

        self.declare_parameter("param_name","heizige") # 声明参数
        self.param_name=self.get_parameter("param_name").value # 获取参数

       

        self.add_on_set_parameters_callback(self.paramter_callback) # 添加参数根新回调函数
    
    def paramter_callback(self,parameters):
        from rcl_interfaces.msg import SetParametersResult
        for item in parameters:
            self.get_logger().info(f"参数:{item.name} 设置为:{item.value}")
            if item.name=='param_name':
                self.param_name=item.value
        
        return SetParametersResult(successful=True)
   
   

def main():
    rclpy.init()
    node=ParamTest('param_test')
    
    rclpy.spin(node)

    rclpy.shutdown()